 <?php
// No directAcces
defined('_AppBackMiage') or die('Restricted access');
if(isAdministrateur ()){
    include_once (DS . "backoffice/include/header.php");
    include_once( DS . "backoffice/include/toppanel_portail.php");
    ?>
    <div id="wrapper">
    <div id="content">
        <div id="rightnow">
            <?php
            $title = "Domaines";
            $add = '<a href="' . URL . 'index.php?m=admin_portaildomaine_add" class="add">Ajouter un domaine</a>';
            ?>

            <h3 class="reallynow">
                <span>Liste des <?php echo $title; ?></span>
                <?php echo $add;
                echo $csv; ?>
                <br />
            </h3>
            </p>
            <p class="youhave">
                <?php
                    $nbrResultPerPage = 10;

                    if (isset($_GET['page']) && !empty($_GET['page'])){
                        $page = $_GET['page'];
                        $nbr = (((int) $_GET['page'] - 1) * $nbrResultPerPage);
                        $listeDomaine = DomaineApplication::getList($nbrResultPerPage, $nbr);
                    }
                                        else {
                        $page = 1;
                        $listeDomaine = DomaineApplication::getList($nbrResultPerPage, 0);
                    }

                    $count = DomaineApplication::globalCount();
                    $pages = ceil($count / $nbrResultPerPage);
                    $pageSuivante = $page + 1;
                    $pagePrecendente = $page - 1;
                    if (!empty($listeDomaine)){
                                                ?>
                                                <table width="100%">
                                                        <thead>
                                                                <tr>
                                                                        <th>Domaine d'application</th>
                                                                        <th>Action</th>
                                                                </tr>
                                                        </thead>
                                                        <tbody>
                                                <?php

                                                foreach ($listeDomaine as $domaine){
                                                        $editURL = URL . "/index.php?m=admin_portaildomaine_edit&uid=".$domaine->idDomaineApplication;
                                                ?>
                                                                <tr>
                                                                        <td ><?php echo $domaine->NomDomaineApplication; ?></td>
                                                                        <td class="a-center">
                                                                                <a href="<?php echo $editURL; ?>">
                                                                                        <img src="<?php echo STYLEBK; ?>img/icons/user_edit.png" title="Edit domaine" width="16" height="16" />
                                                                                </a>
                                                                        </td>
                                                                </tr>
                                        <?php
                                        }
                                        ?>
                            </tbody>
                     </table>

                         <div id="pager">
                        Page
                        <?php
                        if ($pagePrecendente > 0): ?>
                            <a href=<?php echo URL . "/index.php?m=admin_portaildomaine_list&page=" . $pagePrecendente; ?>><img src="<?php echo STYLEBK; ?>			    			img/icons/arrow_left.gif" width="16" height="16" /></a>
                        <?php
                        endif;
                        echo $page;
                        if ($pageSuivante <= $pages): ?>
                            <a href="<?php echo URL . "/index.php?m=admin_portaildomaine_list&page=" . $pageSuivante; ?>"><img src="<?php echo STYLEBK; ?>img/icons/arrow_right.gif" width="16" height="16" /></a>
                        <?php
                        endif;
                        ?>
                        sur <?php echo $pages; ?> | Total <strong><?php echo $count; ?> </strong> domaines trouv&eacute;s.
                    </div>
                    <?php
                                        }
                                        else{
                                                echo 'rien';
                                        }
                                ?>
                </p>
            </div>
        </div>
    <?php
    include_once (DS . "backoffice/include/sidebar.php");
    include_once (DS . "backoffice/include/footer.php");
}
else
{
    redirectTo(URLBACK);
}
?>
